package org.voidness.oje2d;

public class GLFlyingText extends GLTimedText {
    private boolean fade;

    private float alpha;

    private int maxOffset;

    private float offset;

    private float zoomFactor;

    private float zoom;

    private long currentMotionTime;

    private long lastMotionTime;

    private long movementInterval;

    public GLFlyingText(String mText, GLFont mFont, long mTimeToLive,
            boolean mFade, int mMaxOffset, float mStartZoom, float mEndZoom) {
        super(mText, mFont, mTimeToLive);
        fade = mFade;
        alpha = 1.0f;
        maxOffset = mMaxOffset;
        offset = 0;
        zoom = mStartZoom;
        zoomFactor = (mEndZoom - mStartZoom) / maxOffset;

        currentMotionTime = Utils.getTime();
        lastMotionTime = currentMotionTime;

        movementInterval = mTimeToLive / mMaxOffset;
    }

    public void draw(int mX, int mY, GLColor mColor) {
        if ((currentMotionTime = Utils.getTime()) - lastMotionTime > movementInterval / 1000) {
            if (fade) {
                alpha -= 1.0f / maxOffset;
                mColor.setAlpha(alpha);
            }

            offset += 2;
            // if (offset > maxOffset)
            // dead = true;

            zoom += zoomFactor;

            lastMotionTime = currentMotionTime;
        }

        draw((int) (mX - zoom * text.length() * 7), mY - (int) offset, zoom,
                mColor);
    }

}
